<form id="promotion_form" name="promotion_form" action="index.php?app=starbuy&ctl=admin_promotion&act=save_rule"  method="POST" >
<input type="hidden" name="ruledata[special_id]" value="<{$ruleInfo.special_id}>">
<div class="tableform">
<div class="division">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
  <th><em><font color='red'>*</font></em><{t}>规则名称：<{/t}></th>
  <td><{input type="text" name="ruledata[name]" style="width:120px" required="true" vtype='required' value=$ruleInfo.name}></td>
</tr>
<!--
<tr>
  <th><{t}>优先级：<{/t}></th>
  <td><{input type="unsignedint" name="ruledata[ordernum]"  value=$ruleInfo.ordernum maxlength="5" size="3"}></td>
</tr>
-->
<tr>
  <th><em><font color='red'></font></em><{t}>规则描述：<{/t}></th>
  <td><{input class="inputstyle" type="html" name="ruledata[description]" value=$ruleInfo.description}></td>
</tr>

<!--
<tr>
  <th><em><font color='red'></font></em><{t}>自提时间：<{/t}></th>
  <td><{input type="textarea"  style=" width:50%" class="inputstyle" name="from_extract" value=$ruleInfo.from_extract}>
  <div class="font-gray">多条数据以','号隔开</div>
  </td>
</tr>
-->

<tr>
  <th><em><font color='red'>*</font></em><{t}>启用状态：<{/t}></th>
  <td><{input type="bool" name="ruledata[status]" value=$ruleInfo.status}></td>
</tr>

<tr>
    <th><em><font color='red'>*</font></em><{t}>移动端轮播图片：<{/t}></th>
    <td>
        <div class="division pic-main" style="margin:0;position:relative">
            <div class="clearfix">
              <span class="pic-uploader">
                <{button app="desktop" class="btn-upload" label=$___b2c="添加商品图片"|t:'b2c' icon="image_new.gif"}>
              </span>
            </div>

            <div class="pic-area">
                <input type="hidden" name="image_default" value="<{$ruleInfo.images.0}>" />
                <div class="pic-area">
                    <input type="hidden" name="image_default" value="<{$ruleInfo.images.0}>" />
                    <div class='all-pics' style="width:100%">
                        <{if $ruleInfo.images}>
                        <{foreach from=$ruleInfo.images item=gimage}>
                        <div class="gpic-box">
                            <{if $gimage}>
                            <div class="gpic<{if $goods.image_default_id==$gimage}> current<{/if}>" image_id="<{$gimage}>">
                                <img src="<{$gimage|storager:'s'}>" width="88" height="88" sn='_img_<{$gimage}>'/>
                                <i><{t}>默认图<{/t}></i>
                            </div>
                        <input name="goods[images][]" value="<{$gimage}>" soucre="<{$gimage|storager:'b'}>" bigPic="<{$gimage|storager:'b'}>" type="hidden">
                            <div class="gpic-btn-bar">
                                <span class="gpic-btn-delete" ident="<{$gimage}>" onclick="this.getParents('.gpic-box')[0].remove()" title="<{t}>删除图片<{/t}>"><i><{t}>删除图片<{/t}></i></span>
                            </div>
                            <{/if}>
                        </div>
                        <{/foreach}>
                        <{/if}>
                    </div>
                </div>
            </div>

        </div>
    </td>
</tr>

<tr>
  <th><em><font color='red'>*</font></em><{t}>发布时间：<{/t}></th>
  <td><{input type="hour" name="release_time" value=$ruleInfo.release_time vtype="required"}></td>
</tr>

<tr>
  <th><em><font color='red'>*</font></em><{t}>开始时间：<{/t}></th>
  <td><{input type="hour" name="begin_time" value=$ruleInfo.begin_time vtype="required"}></td>
</tr>

<tr>
  <th><em><font color='red'>*</font></em><{t}>结束时间：<{/t}></th>
  <td><{input type="hour" name="end_time" value=$ruleInfo.end_time vtype="required"}></td>
</tr>
<tr>
  <th><{t}>是否设置开团提醒：<{/t}></th>
  <td><{input type="bool" class="act-remind" name="ruledata[remind]" value=$ruleInfo.remind}></td>
</tr>
<tr class="remind" <{if $ruleInfo.remind=='false' || !$ruleInfo.remind}> style="display:none"  <{/if}> >
    <th><{t}>发送开团提醒方式：<{/t}></th>
    <td id="remind">
          <{foreach from=$remind_way item=remind key=key}>
          <label><input type="checkbox" value="<{$key}>" name="ruledata[remind_way][]" <{if ($ruleInfo.remind_way != '') && in_array($key,$ruleInfo.remind_way)}>checked<{else}> <{if $key=="msgbox"}>checked<{/if}><{/if}>/><{$remind}></label>
          <{/foreach}>
      <em><font color='red'>默认站内信提醒</font></em>
    </td>
</tr>

<tr class="remind" <{if $ruleInfo.remind=='false' || !$ruleInfo.remind}> style="display:none"  <{/if}> >
  <th><{t}> 提前多长时间发送开团提醒：<{/t}></th>
  <td><{input type="unsignedint" name="ruledata[remind_time]" vtype="required" value=$ruleInfo.remind_time size="5"}>小时</td>
</tr>

<tr>
  <th><em><font color='red'></font></em><{t}>每人限购：<{/t}></th>
  <td><{input type="unsignedint" name="ruledata[limit]"  value=$ruleInfo.limit size="5"}>件</td>
</tr>

<tr>
  <th><{t}>是否显示倒计时：<{/t}></th>
  <td><{input type="bool" name="ruledata[cdown]" value=$ruleInfo.cdown}></td>
</tr>
<tr>
  <th><{t}>初始销售量：<{/t}></th>
  <{if $ruleInfo.initial_num}>
  <td><{input type="unsignedint" name="ruledata[initial_num]" value=$ruleInfo.initial_num size="5" readonly="true" }> </td>
  <{else}>
  <td><{input type="unsignedint" name="ruledata[initial_num]" value=$ruleInfo.initial_num size="5"}> 或 <{button label="随机生成" class="act-random"}></td>
  <{/if}>
</tr>

<tr>
  <th><{t}>是否开启自动关闭订单功能：<{/t}></th>
  <td><{input type="bool" name="ruledata[iftimeout]" value=$ruleInfo.iftimeout class="act-autoclose"}> &nbsp;
    <{if $ruleInfo.iftimeout == 'true'}>
      <{input type="unsignedint" name="ruledata[timeout]" class="timeout1" value=$ruleInfo.timeout size="5" vtype="required"}>
    <{else}>
      <{input type="unsignedint" name="ruledata[timeout]" class="timeout1" value=$ruleInfo.timeout size="5" vtype="required" style="display:none"}>
    <{/if}>
  </td>
</tr>

<tr>
  <th><{t}>促销类型：<{/t}></th>
  <td>
      <{foreach from=$promotins_type item=name key=id}>
      <input type="radio" vtype="requiredradio" name="ruledata[type_id]" value="<{$id}>" <{if $ruleInfo.type_id == $id}> checked<{/if}> class="act-custom"> <{$name}>
      <{/foreach}>
      <input type="radio" name="ruledata[type_id]" value="other" class="act-custom"> 自定义
      <input type="text" vtype="required" name="ruledata[other]" maxlength='5' size="10" style="display:none">
  </td>
</tr>

<tr>
  <th><{t}>促销商品：<{/t}></th>
  <td>
      <{input type="object" name="ruledata[promotion_pro]" object="goods" app="b2c" select="checkbox" vtype="required" textcol="name" cols="name" filter="goods_type=normal&marketable=true" view="starbuy:admin/promotions/new_items.html"  multiple="true" extend=$extend value=$gids}>
  </td>
</tr>


</table>
</div>
</div>

<{capture name='footbar'}>
<table cellspacing="0" cellpadding="0" class="table-action">
    <tbody><tr valign="middle">
            <td>
                <{assign var="___a"  value="关  闭"}>
                <{assign var="___c"  value=$___b2c='确定退出?'|t:'b2c'}>
                <{button label=$___b2c="保存并关闭窗口"|t:'b2c' class="btn-primary" type="button" id="submitForm" onclick="submitForm(event,2)"}>
                <!--<{button label="保  存" class="btn-primary" onclick="submitForm(event,1)"}>-->
                <{button label=$___content=$___a|t:'content' class="btn-secondary" type="button" onclick="if(confirm('{$___c}'))window.close()"}>
            </td>
        </tr>
    </tbody>
</table>
<{/capture}>
</form>
<script>
 //   validatorMap['requiredradio'] = [LANG_Validate['requiredonly'], function(element) {
 //       var parent =  element.getParent('ul'),radio;
 //       if(element.get('name')) radio = parent.getElements('input[type=radio][name="'+element.get('name')+'"]');
 //       else radio = parent.getElements('input[type=radio]');
 //       return radio.some(function(rd) {
 //           return rd.checked == true;
 //       });
 //   }];

    $$('.act-random').addEvent('click', function(e){
        this.getPrevious('input').set('readonly', true).set('value', Number.random(1, 1000));
    });

    $$('.act-autoclose').addEvent('click', function(e){
        if(this.value == 'true') {
            $$('.timeout1').show();
        }
        else if(this.value == 'false') {
            $$('.timeout1').hide();
        }
    });
    $$('.act-custom').addEvent('click', function(e){
        if(this.value == 'other') {
            this.getNext('input[type=text]').show();
        }
        else {
            this.getNext('input[type=text]').hide();
        }
    });
    $$('.act-remind').addEvent('click', function(e){
        console.log(this.value);
        if(this.value == 'true') {
            $$('.remind').show();
        }
        else {
            $$('.remind').hide();
        }
    });
    var submitForm = function (event,sign){
        var _form=$('promotion_form');

        switch (sign){
            case 1:
            var target={
                onComplete:function(){
                    location.reload();
            }};
            break;
            case 2:
            var target={
                onComplete:function(rs){
                    if(rs&&!!JSON.decode(rs).success){
                        try{
                            window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
                            window.close();
                        }catch(e){}
                    }
            }};
            break;
        }
        _form.store('target',target);
        _form.fireEvent('submit',new Event(event));
    };

 var goodsEditFrame = (function(){
     Ex_Loader('uploader',function(){
         $$('.pic-uploader').each(function(el,j){
             if (document.getElements('.swiff-uploader-box')) {
                 document.getElements('.swiff-uploader-box').destroy();
             }
             var pic_main = el.getParent('.pic-main');
             var area = pic_main.getElement('.pic-area');
             var pics = pic_main.getElement('.all-pics');
             new Swiff.Uploader( {
                 allowDuplicates: true,
                 verbose: true,
                 url:'index.php?app=image&ctl=admin_manage&act=gimage_swf_remote&sess_id='+sess_id,
                 path: '<{$image_dir}>/uploader.swf',
                 typeFilter: {
                     'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'
                 },
                 fileSizeMax:'<{$IMAGE_MAX_SIZE}>',
                 target:el,
                 onSelect:function(rs){
                     if(rs)
                         rs.each(function(v){
                             if(v.size>this.fileSizeMax){
                                 alert(v.name+'<{t}>\n\n文件超出大小<{/t}>');
                             };
                         },this);
                 },
                 onSelectFail:function(rs){
                     rs.each(function(v){
                         if(v.validationError=='sizeLimitMax'){
                             alert(v.name+'<{t}>\n\n文件超出大小<{/t}>');
                         };
                     });
                 },
                 onSelectSuccess:function(rs){
                     var PID='up_';
                     var _this=this;
                     rs.each(function(v,i){
                         new Element('div',{'class':'gpic-box','id':PID+j+v.id}).inject(pics);
                     });
                     this.start();
                 },
                 onFileOpen:function(e){
                     $('up_'+j+e.id).setHTML('<em style="font-size:13px;font-family:Georgia;">0%</em>');
                 },
                 onFileProgress:function(e){
                     $('up_'+j+e.id).getElement('em').set('text',e.progress.percentLoaded+'%');
                 },
                 onFileComplete: function(res){
                     if(res.response.error){
                         return  new MessageBox.error('<{t}>文件<{/t}>'+res.name+'<{t}>上传失败<{/t}>');
                     }
                     $('up_'+j+res.id).setHTML(res.response.text);
                 }
             });

         });

     });
 });
 goodsEditFrame();
</script>

